/**
 * 
 */
package com.example.demo.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cloud.tianai.captcha.slider.SliderCaptchaApplication;
import cloud.tianai.captcha.vo.CaptchaResponse;
import cloud.tianai.captcha.vo.SliderCaptchaVO;

/**
 * @author 030998
 *
 */
@Controller
@RequestMapping("/slider")
public class SliderCaptchaController {

	@Autowired
    private SliderCaptchaApplication sliderCaptchaApplication;

    @GetMapping("/captcha")
    public String index() {
        return "/modules/captcha/list";
    }

    @GetMapping("/gen")
    @ResponseBody
    public CaptchaResponse<SliderCaptchaVO> genCaptcha(HttpServletRequest request) {
        CaptchaResponse<SliderCaptchaVO> response = sliderCaptchaApplication.generateSliderCaptcha();
        return response;
    }

    @GetMapping("/check")
    @ResponseBody
    public boolean checkCaptcha(@RequestParam("id") String id,
                                @RequestParam("percentage") Float percentage,
                                HttpServletRequest request) {
        return sliderCaptchaApplication.matching(id, percentage);
    }
}
